using System;
using System.Collections.Generic;

namespace PetShop.Web.Entities
{
    [Serializable]
    public class CartInfo
    {
        private readonly List<CartItemInfo> _items;

        public CartInfo()
        {
            _items = new List<CartItemInfo>();
        }


        public List<CartItemInfo> Items
        {
            get { return _items; }
        }

        public decimal Total
        {
            get
            {
                decimal total = 0;
                foreach (CartItemInfo item in _items)
                {
                    decimal totalitem = item.Price*item.Quantity;
                    total = total + totalitem;
                }

                return total;
            }
        }

        public int Count
        {
            get { return Items.Count; }
        }

        public CartItemInfo this[int index]
        {
            get { return Items[index]; }
        }

        public void Remove(string itemId)
        {
            foreach (CartItemInfo item in _items)
            {
                if (itemId == item.ItemId)
                {
                    _items.Remove(item);

                    return;
                }
            }
        }

        public void Add(CartItemInfo item)
        {
            _items.Add(item);
        }

        public void RemoveAt(int index)
        {
            CartItemInfo item = _items[index];

            _items.RemoveAt(index);
        }
    }
}